package middleware

import (
	"net/http"
)

// SetRedirectHeader is a middleware that sets an X-Handled-Redirected
// HTTP header when a request contains the "redirected=1" query parameter.
func SetRedirectHeader(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		redirected := r.URL.Query().Get("redirected")

		if redirected == "1" {
			r.Header.Set("X-Handled-Redirected", "true")
		}

		h.ServeHTTP(w, r)
	})
}
